﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace SGArchiveSystem7x.Controllers.WorkSpace
{
    public class AdminWorkSpaceController : BaseController
    {
        // 档案管理员的工作空间
        public ActionResult Index()
        {
            if(Models.Language._nowLanguage == SGArchiveSystem7xDB._VersionLanguage._Chs)
            {
                ViewBag.Text0 = "汇总记录";
                ViewBag.Text1 = "RFID历史总量";
                ViewBag.Text2 = "在库总量";
                ViewBag.Text3 = "出库总量";
                ViewBag.Text4 = "今日入库";
                ViewBag.Text5 = "今日出库";
                ViewBag.Text6 = "最近导入系统物品（前10条）";
                ViewBag.Text7 = "状态";
                ViewBag.Text8 = "类型";
                ViewBag.Text9 = "编号";
                ViewBag.Text10 = "批次号";
                ViewBag.Text11 = "品名";
                ViewBag.Text12 = "导入时间";
                ViewBag.Text13 = "入库时间";
                ViewBag.Text14 = "出库时间";
                ViewBag.Text15 = "最近入库的物品（前10条）";
                ViewBag.Text16 = "最近出库的物品（前10条）";
                ViewBag.Text17 = "整体数据图表";
            }
            else
            {
                ViewBag.Text0 = "Summary Record";
                ViewBag.Text1 = "Historical total";
                ViewBag.Text2 = "In Warehouse total";
                ViewBag.Text3 = "Out Warehouse total";
                ViewBag.Text4 = "Today In total";
                ViewBag.Text5 = "Today Out total";
                ViewBag.Text6 = "Recently imported system items (first 10)";
                ViewBag.Text7 = "Status";
                ViewBag.Text8 = "Type";
                ViewBag.Text9 = "Number";
                ViewBag.Text10 = "Batch Number";
                ViewBag.Text11 = "Name";
                ViewBag.Text12 = "Import Date";
                ViewBag.Text13 = "In Date";
                ViewBag.Text14 = "Out Date";
                ViewBag.Text15 = "Recently In Warhouse items (first 10)";
                ViewBag.Text16 = "Recently Out Warhouse items (first 10)";
                ViewBag.Text17 = "In Warhouse items";
            }

            return View();
        }




        /// <summary>
        /// 柱形图(获取档案分类)
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string Get_ajaxArchivlist()
        {
            System.Data.DataTable dt = SGArchiveSystem7xDB.SQL.T_ArchiveAjSQL.GetArchivlist();
            //int n = dt.Rows.Count;
            //string[] categories = new string[n];
            //int[] data = new int[n];
            try
            {
                string[] strs = new string[2];


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strs[1] += int.Parse(dt.Rows[i].ItemArray[0].ToString()) + ",";
                    strs[0] += dt.Rows[i].ItemArray[1].ToString() + ",";
                }
                strs[0] = strs[0].TrimEnd(',');
                strs[1] = strs[1].TrimEnd(',');

                return strs[0] + "|" + strs[1];
            }
            catch { return "0|0"; }
        }


        public string Get_ajaxvArchivCount() {

            try
            {
                //DataTable dt = SGArchiveSystem7xDB.SQL.T_ArchiveAjSQL.GetArchivCountlist();
                DataTable dt = SGArchiveSystem7xDB.SQL.T_ArchiveAjSQL.GetBorrowList();

                string[] str = new string[1];
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        str[0] += int.Parse(dt.Rows[i].ItemArray[j].ToString())+",";
                    }
                }
                return str[0];
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// 当前档案情况
        /// </summary>
        /// <returns></returns>
        public string Get_ajaxvArchivStatus()
        {
            try
            {
                DataTable dt = SGArchiveSystem7xDB.SQL.T_ArchiveAjSQL.GetBorrowList();

                string[] str = new string[1];
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        str[0] += int.Parse(dt.Rows[i].ItemArray[j].ToString())+",";
                    }
                }
                return str[0];
            }
            catch (Exception)
            {
                return null;
            }
           
        }

        [HttpPost]
        public string Get_ajaxNoSQ()
        {
            try
            {
                string s = SGArchiveSystem7xDB.SQL.T_ArchiveAjSQL.GetNoSQList();
                return s;
                //string[] str = new string[1];
                //for (int j = 0; j < dt.Columns.Count; j++)
                //{
                //    for (int i = 0; i < dt.Rows.Count; i++)
                //    {
                //        str[0] += int.Parse(dt.Rows[i].ItemArray[j].ToString()) + ",";
                //    }
                //}
                //return str[0];
            }
            catch (Exception)
            {
                return "0";
            }

        }



        /// <summary>
        /// 申请借阅(等到冲击力的)
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string Get_ajaxArchivApplicationList()
        {
            try
            {
                DataTable dt = SGArchiveSystem7xDB.SQL.T_ArchiveAjSQL.Get_ArchivsApplication();
                System.Text.StringBuilder jsonBuilder = new System.Text.StringBuilder();
                jsonBuilder.Append("{");
                jsonBuilder.AppendFormat("\"total\":{0}, ", dt.Rows.Count);
                jsonBuilder.Append("\"rows\":[ ");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    jsonBuilder.Append("{");
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        jsonBuilder.Append("\"");
                        jsonBuilder.Append(dt.Columns[j].ColumnName);
                        jsonBuilder.Append("\":\"");
                        jsonBuilder.Append(dt.Rows[i][j].ToString());
                        jsonBuilder.Append("\",");
                    }
                    jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                    jsonBuilder.Append("},");
                }
                jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                jsonBuilder.Append("]");
                jsonBuilder.Append("}");
                return jsonBuilder.ToString();
            }
            catch (Exception)
            {
                return null;
            }
          
        }


        /// <summary>
        /// 今日到期的借阅
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string Get_ajaxArchivExpirationList()
        {
            try
            {
                DataTable dt = SGArchiveSystem7xDB.SQL.T_ArchiveAjSQL.Get_ArchivsExpiration();
                System.Text.StringBuilder jsonBuilder = new System.Text.StringBuilder();
                jsonBuilder.Append("{");
                jsonBuilder.AppendFormat("\"total\":{0}, ", dt.Rows.Count);
                jsonBuilder.Append("\"rows\":[ ");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    jsonBuilder.Append("{");
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        jsonBuilder.Append("\"");
                        jsonBuilder.Append(dt.Columns[j].ColumnName);
                        jsonBuilder.Append("\":\"");
                        jsonBuilder.Append(dt.Rows[i][j].ToString());
                        jsonBuilder.Append("\",");
                    }
                    jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                    jsonBuilder.Append("},");
                }
                jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                jsonBuilder.Append("]");
                jsonBuilder.Append("}");
                return jsonBuilder.ToString();
            }
            catch (Exception)
            {
                return null;
            }

            
        }


        /// <summary>
        /// 当前逾期
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string Get_ajaxArchivOverdueList()
        {
            try
            {
                DataTable dt = SGArchiveSystem7xDB.SQL.T_ArchiveAjSQL.Get_ArchivsOverdue();
                System.Text.StringBuilder jsonBuilder = new System.Text.StringBuilder();
                jsonBuilder.Append("{");
                jsonBuilder.AppendFormat("\"total\":{0}, ", dt.Rows.Count);
                jsonBuilder.Append("\"rows\":[ ");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    jsonBuilder.Append("{");
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        jsonBuilder.Append("\"");
                        jsonBuilder.Append(dt.Columns[j].ColumnName);
                        jsonBuilder.Append("\":\"");
                        jsonBuilder.Append(dt.Rows[i][j].ToString());
                        jsonBuilder.Append("\",");
                    }
                    jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                    jsonBuilder.Append("},");
                }
                jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                jsonBuilder.Append("]");
                jsonBuilder.Append("}");
                return jsonBuilder.ToString();
            }
            catch (Exception)
            {
                return null;
            }
         
        }

        /// <summary>
        /// 个人的工作空间
        /// </summary>
        /// <returns></returns>
        public ActionResult UserWorkSpace()
        {
            return View();
        }
    }
}